package com.qf.aspect;
/*
只通过注解快速方便的设置切面编程 ，Spring配置文件中省略
 */
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect  //声明此类是一个切面类：会包含切入点---pointcut和通知---advice
@Component //声明组件 进入工厂
public class MyAspect {
    //定义切入点
    @Pointcut("execution(* com.qf.service.stuServiceImple.StuServiceImpl.*(..))")
    public void pc() {
    }

//    @Before("pc()")//前置通知
//    public void mybefore(JoinPoint a) {
//        System.out.println("target:" + a.getTarget());
//        System.out.println("target:" + a.getArgs());
//        System.out.println("method's name:" + a.getSignature().getName());
//        System.out.println("before~~~~");
//    }
//
//    @AfterReturning(value = "pc()", returning = "ret") //后置通知
//    public void myAfterReturning(JoinPoint a, Object ret) {
//        System.out.println("after~~~:" + ret);
//    }
//
    @Around("pc()") //环绕通知
    public Object myInterceptor(ProceedingJoinPoint p) throws Throwable {
        System.out.println("interceptor1~~~~~");
        Object proceed = p.proceed();
        System.out.println("interceptor2");
        return proceed;

    }
//
//    @AfterThrowing(value = "pc()", throwing = "ex") //异常通知
//    public void myThrows(JoinPoint jp, Exception ex) {
//        System.out.println("throws");
//        System.out.println("====" + ex.getMessage());
//    }
}
